
app.controller('kmCtrl',function($scope,$http){
	var x = 0;
	var kbol = true;
	//右点击
	function kll(){
		if(kbol==true){
			kbol = false;
			x++;
		var w = $('.k_lunbo img').eq(0).width();
		$('.k_lunbo').animate({'left':-x*w+'px'},1000,function(){
			if(x==4){
			x=0;
			$('.k_lunbo').css('left',0);			
		};
		kbol = true;
		$('.k_big ul li').css('background','red')
		$('.k_big ul li').eq(x).css('background','cyan')
		});
		}
		
	};
	$('.k_right').click(function(){
		kll();
	})
	
	//左点击
	$('.k_left').click(function(){
		if(kbol==true){
			x--;	
			console.log(x)
			kbol==false;
			var w = $('.k_lunbo img').eq(0).width();
		$('.k_big ul li').css('background','red')
		$('.k_big ul li').eq(x).css('background','cyan')
		if(x==-1){
			
			x=4;
			$('.k_lunbo').css('left',-x*w+'px');
			$('.k_lunbo').animate({'left':-3*w+'px'},1000,function(){		    kbol==true;
				x=3;
		});	
		}else{
		
			$('.k_lunbo').animate({'left':-x*w+'px'},1000,function(){		    kbol==true;
		});	
		}
		}
		
	});
	$('.k_big ul li').each(function(i,e){
		$(e).click(function(){
			$('.k_big ul li').css('background','red')
		    $(e).css('background','cyan')
		    var w = $('.k_lunbo img').eq(0).width();
		    $('.k_lunbo').css('left',-i*w)
		    x=i;
		})
	})
	//计时器
	var timer = setInterval(function(){
		kll();
		host()
	},3000);
	//跳转清除
	$scope.$on('$destroy', function() {
		clearInterval(timer);
	});
	//鼠标移入清除计时器
	$('.k_big').mouseenter(function(){
		clearInterval(timer);
	});
	//鼠标移出
	$('.k_big').mouseleave(function(){
		timer = setInterval(function(){
		kll();
	},3000);
	})
	//
     $http.get('../php/k_main.php?kkk=8').success(function(data){
     	$scope.kdm1 = data;
     });
     $http.get('../php/k_main.php?kkk=4').success(function(data){
     	$scope.kdm2 = data;
     })
	//热卖
	var timer1 = setInterval(function(){
     	var tomorrow = new Date('2017-7-5 0:0:0');
        var now = new Date();
        var ttime = tomorrow.getTime();
        var ntime = now.getTime();
        var times = ttime - ntime;
        var d = Math.floor(times/1000/60/60/24);
        var n = Math.floor(times / 1000 / 60 / 60%24);
        var m = Math.floor(times / 1000 / 60 % 60);
        var s = Math.floor(times / 1000 % 3600 % 60);
        $('.k_day').html(d+'天');
        $('.k_hour').html(n);
        $('.k_min').html(m);
        $('.k_sec').html(s);
     },1000);
     //热卖轮播
     var hx = 0;
     function host(){
     	hx++;
     	if(hx==2){
     		hx=0
     	};
     	$('.k_qiang_big').css('left',-1280*hx+'px');
     	$('.k_qiang_con ul li').css("background",'red');
     	$('.k_qiang_con ul li').eq(hx).css("background",'cyan');
     	$('.k_qiang_con ul li').each(function(i,e){
     		$(e).click(function(){
     			$('.k_qiang_big').css('left',-1280*i+'px');
     			hx=i;
     			$('.k_qiang_con ul li').css("background",'red');
     	$('.k_qiang_con ul li').eq(i).css("background",'cyan');
     		})
     	})
     }
     
})
